<template>
  <dialog-editor ref="dialog"></dialog-editor>
</template>

<script>
import DialogEditor from '@/components/DialogEditor'
import dialogMixins from '@/utils/commonDialogMixins'
import {mRequest} from '@/utils/request'

export default {
  mixins: [dialogMixins],
  components: {DialogEditor},
  data() {
    return {
      visible: false,

      dataFormConfig: {
        // personName: {
        //   label: '申请付款人',
        //   placeholder: '请输入申请付款人'
        // },
        /**
         *             {'id': 0,name:'私户'},
         *             {'id': 1,name:'公户'},
         *             {'id': 2,name:'微信'},
         *             {'id': 3,name:'支付宝'},
         */
        //
        payAccount: {
          label: '支出账户',
          type: 'list',
          list: []
        },

        category: {
          label: '支出类别',
          type: 'list',
          filterable: true,
          placeholder: '请选择纸类别',
          list: []
        },
        payDate: {
          label: '付款日期',
          type: 'date',
          placeholder: '请输入付款日期'
        },
        purchaseContractId:{
          label: '合同编号',
          type: 'list',
          filterable: true,
          list: [],
          placeholder: '请输入合同编号',
          selectCallback: this.purchaseContractIdSelectCallback

        },

  /*      customerName: {
          label: '收款人名称',
          placeholder: '请输入收款人名称'
        },*/
        supplierId: {
          label: '收款人名称',
          type: 'list',
          filterable: true,
          list: [],
          placeholder: '请输入收款人名称',
          selectCallback: this.supplierIdSelectCallback

        },


        amount: {
          label: '金额',
          type: 'number',
          default: 0,
          min: -10000,
          max:100000000,
          placeholder: '请输入金额'
        },
        paymentAmount: {
          label: '合同已付金额',
          type: 'number',
          default: 0,
          max:100000000,
          disabled:true,
          placeholder: '请输入合同已付金额'
        },
        payInfo: {
          label: '打款信息',
          placeholder: '请输入打款信息',
          inputType: 'textarea'

        },
        remark: {
          label: '备注',
          placeholder: '请输入备注',
          inputType: 'textarea'

        },
        status: {
          label: '状态',
          type: 'switch',
          activeValue: 1,
          inactiveValue: 0,
          default: 1
        }
      }
    }
  },
  methods: {
    amountChanged() {
      const number = this.R.propOr(0, 'number', this.dataForm)
      const price = this.R.propOr(0, 'price', this.dataForm)

      this.dataForm['amount'] = number * price
    },
    init(id) {
      this.dataForm.id = id || 0
      this.initFinanceCategoryList('category')
      this.initSupplierList('supplierId')
      this.initFinanceAccountInfoList('payAccount')
      this.initContractPurchaseInfoList('purchaseContractId')

      this.$refs.dialog.initDialog({
        dataForm: this.dataForm,
        config: this.dataFormConfig,
        dataRule: this.getNeedDataRule('payAccount','payDate', 'customerName', 'amount','purchaseContractId', 'category'),
        initApi: 'financeApi/financePayInfo',
        saveApi: 'financeApi/saveFinancePayInfo',
        updateApi: 'financeApi/updateFinancePayInfo',
        objectName: 'financePay'
      })
    },
    supplierIdSelectCallback() {
      // this.orderSelectHandle(this.dataForm.orderDetailId, (data) => {
      //   this.dataForm['productId'] = this.R.pathOr(0, ['orderDetail', 'productId'], data)
      //   this.dataForm['productWeight'] = this.R.pathOr(0, ['orderDetail', 'productWeight'], data)
      //   this.dataForm['unitPrice'] = this.R.pathOr(0, ['orderDetail', 'unitPrice'], data) == 0 ? undefined : this.R.pathOr(0, ['orderDetail', 'unitPrice'], data)
      //   this.dataForm['orderProductNumber'] = this.R.pathOr(0, ['orderDetail', 'orderProductNumber'], data)
      // })
    },

    purchaseContractIdSelectCallback() {

      mRequest('contractApi/contractPurchaseInfoInfo', {id: this.dataForm.purchaseContractId}, ({data}) => {
         this.dataForm['paymentAmount'] = this.R.pathOr(0, ['contractPurchaseInfo', 'paymentAmount'], data)
        this.dataForm['supplierId'] = this.R.pathOr('', ['contractPurchaseInfo', 'supplierId'], data)
      })
    }
  }
}
</script>
